

# Info：搜索当前CMakeLists.txt文件夹中的子项目并add_subdirectory
# usage: cmake_language(CALL SUBDIR_LIST)
function(SUBDIR_LIST)
	FILE(GLOB children RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)
	SET(dirlist "")
	FOREACH(child ${children})
		IF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${child})
			LIST(APPEND dirlist ${child})
		ENDIF()
	ENDFOREACH()
	FOREACH(src_dir ${dirlist})
		IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${src_dir}/CMakeLists.txt")
			add_subdirectory(${src_dir})
		ENDIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${src_dir}/CMakeLists.txt")
	ENDFOREACH()

endfunction()

# precondition: 每个子目录的文件夹名字和target名字相同
# Info: 		遍历子目录，获取target名
function(LOOP_SUBDIR_GET_TARGET TARGET_NAMES)
	FILE(GLOB children RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*)
	SET(dirlist "")
	FOREACH(child ${children})
		IF(IS_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${child})
			LIST(APPEND dirlist ${child})
		ENDIF()
	ENDFOREACH()
	SET(tgt_list "")
	FOREACH(src_dir ${dirlist})
		IF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${src_dir}/CMakeLists.txt")
			LIST(APPEND tgt_list ${src_dir})
		ENDIF(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/${src_dir}/CMakeLists.txt")
	ENDFOREACH()
	set(TARGET_NAMES  ${tgt_list} PARENT_SCOPE)
endfunction()





